create y 1976 2013
'importing data from Excel for Indonesia
import  "C:\Users\Maryam\Desktop\BS Studies\PhD Thesis-II\EViews and STATA Progarm Codes\Chapter-9\Chapter 9.xlsx" range="Indonesia"

'***************************************************************************************
'ESTIMATING BALASSA-SAMUELSON EFFECT FOR rer_def_NT, rer_def_T, rop, gdppc, gexp & a_tilde
'**************************************************************************************

'*********************************************
'Single Equation Cointegration Methods
'*********************************************

'******************************************************************
''Graph the suspected cointegrated series together
'******************************************************************
'The first step is to print out a graph of the series.  This is very important!

group g1 rer_def_NT rer_def_T rop gdppc gexp a_tilde
freeze(figure1) g1.line(x)
figure1.setelem(1) lcolor(black) symbol(1) lpat(1)
figure1.setelem(2) lcolor(black) symbol(4) lpat(1)
figure1.setelem(3) lcolor(black) symbol(7) lpat(1)
figure1.setelem(3) lcolor(black)
figure1.options linepat
figure1.addtext(t) rer_def_NT, lnpT & a_tilde (Indonesia & U.S): 1976-2013
figure1.addtext(b) Year
figure1.addtext(l) rer_def_NT
figure1.addtext(l) lnpT
figure1.addtext(r) a_tilde

''*******************************************************
''S1.A.Engle-Granger Approach to Cointegration
'*******************************************************

genr resid = 0
equation eg.ls rer_def_NT c rer_def_T rop gdppc gexp a_tilde
genr EC1 = resid

'First we test if the residuals of above regression are level stationary or not. If yes, next we'll proceed towards estimation of error correction model.

'***************************************************************
'Graph for Indonesia's  EC
'***************************************************************                                               
genr EC1 = EC1
freeze(figure_EC1) EC1.line
figure_EC1.addtext(t) EC1 (Indonesia):  1976-2013
figure_EC1.addtext(b) Year
figure_EC1.addtext(l) EC1
figure_EC1.legend(off)
                                                 
'We see from the FIGURE that EC has time trend to it.  So we would include both an intercept and trend in our unit root regression equtions. 

'*********************************************************************************
'EG Test for Cointegration
'**********************************************************************************
 
freeze(table_9_3_EGC) g1.coint(method=eg)

'The null hypothesis will not be rejected as suggested by sample statistics.

''******************************************
''S1.B.Error Correction Model (ECM)
'*******************************************
''*******************************************************
'Selecting the number of lags in the VAR  *
'*******************************************************
'NOTE: We do this because we need to have the "right" number of lags when it comes time to estimate our VEC model and test for cointegration.

var var1.ls 1 4   g1
freeze(var1_lagtest1) var1.laglen(4)
freeze(var1_lagtest2) var1.testlags

'The laglength test above indicates that the should have VAR has 1 lags.

var var2.ls 1 1  g1
freeze(var2_artest1) var2.correl
freeze(var2_artest2) var2.qstats(12)
freeze(var2_artest3) var2.arlm(12)

'The residuals are white noise. So I am staisfied with the selection of 1 lag.

'We now try different lags of d(rer_def_T) and d(a_tilde), comparing SIC values across specifications.

genr resid = 0
equation eg.ls rer_def_NT c rop gdppc gexp a_tilde
genr ec1 = resid

var table_9_3_eg2a.ls 0 0 d(rer_def_NT)   @  c ec1(-1) d(rer_def_NT(-1)) 

var table_9_3_eg2b.ls 0 0 d(rer_def_NT)   @  c ec1(-1) d(rer_def_NT(-1)) d(rer_def_T(-1)) d(rop(-1)) d(gdppc(-1)) d(gexp(-1)) d(a_tilde(-1))

'The evidence suggests that Model A is best.  Now we test that model for serial correlation.

var table_9_3_eg2a.ls 0 0 d(rer_def_NT)   @   c ec1(-1) d(rer_def_NT(-1)) 
freeze(table_9_3_eg2a_artest1) table_9_3_eg2a.correl
freeze(table_9_3_eg2a_artest2) table_9_3_eg2a.qstats(12)
freeze(table_9_3_eg2a_artest3) table_9_3_eg2a.arlm(12)

'The residuals are absolutely white noise.

''*************************
''Estimating EC Model  
'**************************

'We'll now take the above specified model and turn it into an ECM. We shall run NW-HAC least squares model for establishing error correction mechanism.

'We now estimate the corresponding ECM:

equation table_9_3_ecm.ls(n) d(rer_def_NT) c ec1(-1) d(rer_def_NT(-1)) 

'Note that the SR effect is significant as the EC coefficient is of value -0.34 is statistically significant at 10% significance level.

''**********************************************
''S2.A & S2.B: Obtaining LR Coefficients
'***********************************************
'Now, by employing FMOLS and DOLS cointegration regression estimators, finally we shall calculate our LR coefficient i.e. BS coefficient for Indonesia against U.S.

equation table_9_3_LReqn1_fmols.cointreg(method=fmols) rer_def_NT rer_def_T rop gexp gdppc a_tilde

equation table_9_3_LReqn2_dols.cointreg(method=dols, trend=constant, lag=1,lead=1 ) rer_def_NT rer_def_T rop gexp gdppc a_tilde

'The BS coefficient obtained through FMOLS and DOLS estimators are 0.16 and 0.36 and are statistically insignificant and significant, respectively. Thus, there is MIXED evidence in support of BS effect existing for Indonesia.

''******************************************
'Multivariate Cointegration Approach
'******************************************

''*************************************************************
''Check if the VAR(2) model is dynamically stable
'*************************************************************
freeze(table_9_3_var2_varstable) var2.arroots(graph)

'The model is dynamically stable.

''**********************************************************************
''M1.A & M1.B: Identifying the number of cointegrating vectors
'***********************************************************************
'Having identified the appropriate number of lags to put in, I now go on to test for the appropriate number of cointegrating equations.

freeze(table_9_3_var2_coint) var2.coint(s,1)

'This command estimates all possible combinations of constants and trends in the level data series and the cointegrating equations. All the results indicate 1 cointegrating vectors.
'
'GENERAL NOTE:, in practice, cases 1 and 5 are rarely used. One should use case 1 only if one knows that all series have zero mean. Case 5 may provide a good fit in-sample but will produce implausible forecasts out-of-sample. As a rough guide, use case 2 if none of the series appear to have a trend. For trending series, use case 3 if you believe all trends are stochastic; if you believe some of the series are trend stationary, use case 4.

'Note that the 5 cases are identified under "Johansen cointegration test" in Eviews. They run from most restrictive (no constants in either the level series or CEs) to most general (trend terms in both the level series and CEs).

''******************************************************************
''M2.A, M2.B & M3: Vector Error Correction Model (VECM)
'*******************************************************************

' For estimating the LR relationship, corresponding VEC command is:

var table_9_3_vec_c.ec(c,1)  0 0 rer_def_NT rer_def_T rop gexp gdppc a_tilde
var table_9_3_vec_d.ec(d,1)  0 0 rer_def_NT rer_def_T rop gexp gdppc a_tilde

'CONCLUSION:  I conclude that rer_def_NT and a_tilde are not cointegrated in the Indonesia's data.


